[#import "/framework/JGP.htm"  as JGP]
<!--
项目   jgp-cloud-parent
作者   LOUFEI [Gavin]
时间   2019-11-03
-->
[@JGP.head "修改角色菜单"/]
[@JGP.body]
    <jgp-div _row="['40','*']" _runit="px">
        <jgp-tools slot="1-1">
            <jgp-btn _fn="save">保存</jgp-btn>
        </jgp-tools>
        <jgp-panel slot="2-1" _padding="10px" _border="right">
            <jgp-tree2 _id="tree" _root="菜单树" _single="false" _icon="false"
                       _onload="initTree" _show_root="false"
                       _select_next_level="false"
                       _lazy="false"
                       _url="/sys/menu-api-ctl/query-tree-with-out-platform"></jgp-tree2>
        </jgp-panel>
    </jgp-div>
[/@JGP.body]

[@JGP.foot]
    <script>
        var roleId = ${roleId!'null'};
        var selected;
        function initTree(){
            if(!selected){
                JGP.$get('/security/role-menu-api-ctl/query-menu', {
                        roleId:roleId
                    },
                    function (result) {
                        if(result.flag){
                            selected = result.data.menus;
                            JGP.tree2('tree').setSelectedKeys(selected);
                        }
                    })
            }
        }
        function save() {
            var selected = JGP.tree2('tree').getSelected();
            if (selected === -1) {
                JGP.$warn('没有选择角色');
                return;
            }
            var menuIds = [];
            for (var i = 0; i < selected.length; i++) {
                menuIds.push(selected[i].id);
            }
            JGP.$postJson('/security/role-menu-api-ctl/modify-role-menu', {
                    menuIds: menuIds,
                    roleId: roleId
                },
                function (result) {
                    JGP.$alert('角色修改成功');
                }, function () {
                    JGP.$error('错误');
                })

        }
    </script>
[/@JGP.foot]